﻿namespace DotRas
{
    using System;
    using System.Runtime.Serialization;
    using System.Security.Permissions;

    [Serializable]
    public class InvalidHandleException : Exception
    {
        private RasHandle _handle;

        public InvalidHandleException()
        {
        }

        public InvalidHandleException(RasHandle handle) : this(handle, null)
        {
        }

        public InvalidHandleException(string message) : base(message)
        {
        }

        public InvalidHandleException(RasHandle handle, string message) : this(handle, message, null)
        {
        }

        protected InvalidHandleException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            this.Handle = (RasHandle) info.GetValue("Handle", typeof(RasHandle));
        }

        public InvalidHandleException(string message, Exception innerException) : base(message, innerException)
        {
        }

        public InvalidHandleException(RasHandle handle, string message, Exception innerException) : base(message, innerException)
        {
            this.Handle = handle;
        }

        [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.SerializationFormatter)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info != null)
            {
                info.AddValue("Handle", this.Handle, typeof(RasHandle));
            }
            base.GetObjectData(info, context);
        }

        public RasHandle Handle
        {
            get
            {
                return this._handle;
            }
            private set
            {
                this._handle = value;
            }
        }
    }
}

